﻿@inject NavigationManager NavigationManager
@inject IUserAuthenService _userAuthenService
@inherits BaseComponent
<div class="top-row">
    <div class="login-display">
        <div class="login-display-content">
            <a title="" data-toggle="tooltip" data-original-title="点击展开收缩左侧菜单" onclick="showMenu(this)" class="layout-header-bar"><!--!--><i class="fa fa-bars"></i></a>
            <AuthorizeLayout>
                <Authorized>
                    <div class="login-display-parent">
                        <div class="left">
                            <MenuString></MenuString>
                        </div>
                        <div class="center" id="header-center">
                        </div>
                        <div class="right">
                            <div style="padding: 0px; margin-top: -5px;">
                                <Avatar Url="_content/CyssBlazor.Shared/img/user-women.jpg" IsCircle="true" Size="Size.ExtraLarge" />
                                <ButtonDropdown Text="@UserName">
                                    <ButtonDropdownItem Text="修改密码" OnClickWithoutRender="Open"> </ButtonDropdownItem>
                                    <ButtonDropdownItem Text="退出" OnClickWithoutRender="Logout"> </ButtonDropdownItem>
                                </ButtonDropdown>

                            </div>
                        </div>
                    </div>
                </Authorized>
            </AuthorizeLayout>
        </div>
    </div>
</div>

@code
{
    public string UserName { set; get; }

    protected async override Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            var user = await _userAuthenService.GetCurrentUserAsync();
            if (user!=null) UserName=user.Name;
            StateHasChanged();
        }
    }

    public async Task Logout()
    {
        await _userAuthenService.LogoutAsync();
        NavigationManager.NavigateTo("/login");
    }

    public async Task Open()
    {
        //await this.ShowModal<EditPassword>("修改密码", null, Size.ExtraSmall);
    }

}